
/***************************************************************************
**
** Copyright 2002 by Hellosoft Inc. All rights reserved. No part
** of this publication, or any software included with it, may be
** reproduced, stored in a retrieval system, or transmitted in
** any form or by any other means, including photocopying,
** electronic or mechanical recording or otherwise, without
** prior written permission of the copyright holder
**
** Hellosoft Confidential and Proprietary information
**
** File            : wlan_phy_mac.h
**
** Start Date    : Fri Jan 4 2002
**
** Email        : wlan-nw@hyd.hellosoft.com
**
***************************************************************************/

#ifndef __WLAN_PHY_MAC_HEADER__
#define __WLAN_PHY_MAC_HEADER__
#include "hs_types.h"
#include "HsTypes.h"
            /* Constants */
/* preamble type */
#define SHORT_PREAMBLE                            1
#define LONG_PREAMBLE                            0


#define TXDATARATE                            0
#define SHORTPREAMBLE_ATTRIBUTE                        1
#define PBCCMODULATION_ATTRIBUTE                    2
#define INVALID_ATTRIBUTE                        3
#define NO_READ_OPTION                            4
#define PLME_GET_SUCCESS                        5

#define SHORT_PREAMBLE_IMPLEMENTED                    1
#define SHORT_PREAMBLE_NOT_IMPLEMENTED                                  0

/* modulation type */
#define PBCCMODULATION_NOT_IMPLEMENTED                                  0
#define PBCCMODULATION_IMPLEMENTED                    1

/* data rate */
#define MBPS1                                0x0a   // 10
#define MBPS2                                0x14   // 20
#define MBPS5_5                                0x37   // 55
#define MBPS11                                0x6e   // 110

//### TODO change default data rate
#define DEFAULT_DATA_RATE                   MBPS11
#define AUTO_DATA_RATE                      DEFAULT_DATA_RATE

#define MIN_DATA_RATE                       MBPS1
#define MAX_DATA_RATE                       MBPS11

/* for PHY Power Management states*/
#define PHY_WAKE_UP                            1
#define PHY_DOZE                            2

/* values of channel_status */
#define CHANNEL_FREE                        0
#define CHANNEL_BUSY                        1

/* values of rx_result */
#define NOERROR                            0
#define FORMAT_VIOLATION                    1
#define CARRIER_LOST                        2
#define UNSUPPORTED_RATE                    3
#define NOTDESTINED                        4
#define ACKDESTINED                        5
#define CTSDESTINED                        6

#define TXSTART_SUCCESS                        1
#define TXSTART_FAILURE                        0
#define PACKETINERROR                        4  /*added by Kiran*/

/* PHY Layer defines */
#define PMD_SLOT_TIME_MICROSEC                  20
#define PMD_SIFS_TIME_MICROSEC                    10
#define PMD_CCA_TIME_MICROSEC                    15
#define PMD_RX_TX_TURNAROUND_TIME_MICROSEC            5
#define PMD_TX_PLCPDELAY_TIME_MICROSEC                5
#define PMD_RX_PLCPDELAY_TIME_MICROSEC              25
#define PMD_RX_TX_SWITCH_TIME_MICROSEC                5
#define PMD_TX_RAMP_ON_TIME_MICROSEC                5
#define PMD_TX_RAMP_OFF_TIME_MICROSEC               10
#define PMD_TX_RF_DELAY_TIME_MICROSEC                5
#define PMD_RX_RF_DELAY_TIME_MICROSEC               25
#define PMD_AIR_PROPOGATION_TIME_MICROSEC            1
#define PMD_MAC_PROCESSING_DELAY_TIME_MICROSEC                  0
#define PMD_PREAMBLE_LENGTH_TIME_MICROSEC                       144
#define PMD_PLCP_HEADER_LENGTH_TIME_MICROSEC                    48
#define PMD_MPDU_DURATION_FACTOR_TIME_MICROSEC                  0
#define PMD_MPDU_MAXLENGTH_TIME_MICROSEC                        50
#define PMD_CW_MIN_TIME_MICROSEC                31
#define PMD_CW_MAX_TIME_MICROSEC                                1023

/* API code for primitives between MAC and PHY */

#define MAC_PHY_TXSTART_REQUEST                     0x01
#define MAC_PHY_TXSTART_CONFIRM                     0x02
#define    MAC_PHY_CCA_INDICATION                     0x03
#define    MAC_PHY_RXEND_INDICATION                 0x04
#define    MAC_PHY_CCA_RESET_REQUEST                 0x05
#define    MAC_PHY_CCA_RESET_CONFIRM                 0x06
#define    MAC_PHY_CONFIG                             0x07
#define MAC_PLME_CHARACTERISTICS_REQUEST         0x08
#define MAC_PLME_RESET_REQUEST                   0x09
#define PLME_GET_REQUEST                         0x0a

#define MAC_PHY_INTERRUPT                         0x0b
#define MAC_PHY_TXSTART_INTERRUPT                0x0c
#define UART_PHY_INTERRUPT                         0x0d
#define CCA_REG_MSG                         0x0d


/* Data structures */

/* structure used for transmit function TXSTART_request */
typedef struct TXVECTOR{
    HS_UINT16     data_rate;                                      /* data rate to transmit */
    HS_UINT16     length;                        /* total MAC data length to transmit */
    HS_UINT16    preamble_type;                    /* short or long preamble */
    HS_UINT16    modulation_type;                /* type of modulation */
}TXVECTOR;

/* structure used for receive function RXSTART_indication */
typedef struct RXVECTOR{
    HS_UINT16     data_rate;                        /* rate at which data is received */
    HS_UINT16     length;                            /* total MAC data length to receive */
    HS_UINT16    preamble_type;                    /* short or long preamble */
    HS_UINT16    modulation_type;                /* type of modulation */
}RXVECTOR;


    /* Functions */

/* for transmission of a packet */
HS_VOID PHY_TXEND_request(HS_VOID);                            /* MAC informs PHY end of data transmission */

/* for channel status */
HS_VOID PHY_CCARESET_request(HS_VOID);                        /* MAC informs PHY to reset the CCA state */

/* Management entity functions */

HS_VOID PLME_RESET_request(HS_VOID);                        /* MLME requests the PHY to reset to receive state */
HS_VOID PLME_CHARACTERISTICS_request(HS_VOID);                /* MLME requests PHY for the PHY characteristics */

HS_VOID PLME_CHARACTERISTICS_confirm(
                                      HS_INT32 aSlotTime,
                                      HS_INT32 aSIFSTime,
                                      HS_INT32 aCCATime,
                                      HS_INT32 aRxTxTurnaroundTime,
                                      HS_INT32 aTxPLCPDelay,
                                      HS_INT32 aRxPLCPDelay,
                                      HS_INT32 aRxTxSwitchTime,
                                      HS_INT32 aTxRampOnTime,
                                      HS_INT32 aTxRampOffTime,
                                      HS_INT32 aTxRFDelay,
                                      HS_INT32 aRxRFDelay,
                                      HS_INT32 aAirPropagationTime,
                                      HS_INT32 aMACProcessingDelay,
                                      HS_INT32 aPreambleLength,
                                      HS_INT32 aPLCPHeaderLength,
                                      HS_INT32 aMPDUDurationFactor,
                                      HS_INT32 aMPDUMaxLength,
                                      HS_INT32 aCWmin,
                                      HS_INT32 aCWMax
                                    ); /* PHY gives PHY characteristics to MAC */

HS_VOID PLME_GET_request(HS_INT32 MIBAttribute);    /* request to get the attribute values from physical layer to MAC */

HS_UINT16 PLME_TXTIME_request(TXVECTOR *tx_vector);    /* MAC requests PHY to calculate Tx time required */

/* HS_VOID PHY_DATA_request(HS_UINT8 tx_byte);  puts transmit data request by MAC to PHY */
HS_VOID PLME_GET_request(HS_INT32 );

HS_VOID MLME_PLME_POWERMGT_request(HS_INT32 ); /* puts change of power management request*/

HS_INT32 get_plme_cfm_wait_state(HS_VOID); /* returns the plme confirmation wait state */
/* HS_VOID set_plme_cfm_wait_state(HS_UINT32 state); */

HS_VOID set_plme_char_cfm_wait(HS_INT32 state); /* returns the plme confirmation wait state for the
plme characteristics request */
HS_VOID set_plme_datarate_cfm_wait(HS_INT32 state); /* returns the plme confirmation wait state for the
plme data rate request */
HS_VOID set_plme_preamble_cfm_wait(HS_INT32 state); /* returns the plme confirmation wait state for the
plme preamble request */
HS_VOID set_plme_modulation_cfm_wait(HS_INT32 state); /* returns the plme confirmation wait state for the
plme modulation request */

HS_VOID initpmdlayer(HS_VOID); /* for initialising the PMD layer */

HS_VOID  STA_data_rate_set(HS_INT32 mbps);  /* sets the STA's data rate set */
HS_INT32 STA_data_rate_get() ;
HS_INT32 STA_data_rate_max_get() ;

HS_INT32 check_data_or_rts_packet(HS_UINT8 *temp_msg_lp, HS_UINT8 **send_pkt_ptr, HS_INT32 *len, HS_INT32 *rate);


HS_VOID update_MAC_data(HS_INT8   *data, HS_UINT32 length);
HS_VOID update_PHY_data(HS_INT8   *data, HS_UINT32 length);
HS_VOID update_MAC_status(HS_INT8 *data, HS_UINT32 length);
HS_VOID update_PHY_status(HS_INT8 *data, HS_UINT32 length);

HS_VOID init_wlan_phy_mac_variables(HS_VOID);

HS_VOID set_MAC2PHY_interrupt();
HS_INT32 check_MAC2PHY_interrupt();

/** structure to communicate between L1ctrol and TX PHY **/
typedef struct Mac2PhyStruct {
    volatile HS_UINT8 mac2phy_interrupt_register;
    volatile HS_INT32 mac2phy_tx_len;
    volatile HS_INT32 mac2phy_tx_buffer_ptr;
    volatile HS_INT32 mac2phy_tx_rate;
    volatile HS_INT32 start_transmit;
} Mac2PhyStruct;


HS_VOID set_tpu_mhz(HS_INT32 mhz);
HS_VOID upscale_tpu_mhz(HS_INT32 scale);
HS_VOID downscale_tpu_mhz(HS_INT32 scale);


extern Mac2PhyStruct mac2phy_struct;

extern volatile HS_UINT32 mac_init_done;
extern volatile HS_UINT32 mac_memory_init_done;

extern volatile HS_UINT32 uart2phy_interrupt_register_global;
extern volatile HS_UINT32 cca_msg_register_global;
extern volatile HS_UINT32 mac2phy_interrupt_register_global;

extern volatile HS_UINT32    rx_status_global;
extern volatile HS_UINT32     *cca_msg_reg;
extern volatile HS_UINT8        *mac2phy_msg_location;
extern volatile HS_UINT8        *shared_mem_gp;
extern volatile HS_UINT8        *cca_indication_msg_box_gp;
extern volatile HS_UINT8        *data_msg_box_gp;
extern volatile HS_UINT8        *msg_indication_register_gp;

#endif
